<%
    def columns=tableDefine.columns
    def pkColumn=tableDefine.getPkColumn();
    def varDomainName=tableNameUtil.lowerCaseFirst(tableDefine.id)
    def urlPrefix=PubUtils.addStrBeforeSeparator(PubUtils.packageToPath(config.category),".")+varDomainName
%>
<template>
    <el-form :model="${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm" :rules="rules" ref="${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm" label-width="160px">
        <%
            def list = [0,1,2];
            def listOuter = [];
            def cnt = 0
            def columnsize = 0
            def listvariable = 0;
            // 算下有几个card
            def cardCount = columns.size/9;
            def count = cardCount;
            for (int i = 0; i < count; i++) {
                listOuter.add(1);
            };
            listOuter.each{
                println """  <el-card class="box-card" shadow="never" font-size="14px">
                <div slot="header" class="clearfix" >
                    <span>根据需要填写</span>
                </div>
                <div class="tagStyle">  """;
                list.each{
                    def listColum = [];
                    list.each{
                        listColum.add(columns[listvariable])
                        listvariable++;
                    }
                    println """  <el-row type="flex" class="row-bg" justify="start">  """;
                    listColum.each {
                        if (columnsize < columns.size()){
                            if (pkColumn == it) {

                            } else {
                                if (it.jspTag == 'TEXT') {
                                    println """  <el-col :span="7" :offset="1">
                        <el-form-item label="${it.cnname}" prop="${it.dataName}">
                            <el-input type="text" v-model="${
                                        PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)
                                    }AddForm.${it.dataName}" ></el-input>
                        </el-form-item>
                    </el-col>  """;
                                } else if (it.jspTag == 'SELECT') {
                                    println """  <el-col :span="7" :offset="1">
                        <el-form-item label="${it.cnname}" prop="${it.dataName}">
                            <elx-select type="text" v-model="${
                                        PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)
                                    }AddForm.${it.dataName}"
                                             selectKey="自己设置""></elx-select>
                        </el-form-item>
                    </el-col>  """;
                                } else if (it.jspTag == 'TEXTAREA') {
                                    println """  <el-col :span="7" :offset="1">
                        <el-form-item label="${it.cnname}" prop="${it.dataName}">
                            <el-input v-model="${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm.${
                                        it.dataName
                                    }" type="textarea"></el-input>
                        </el-form-item>
                    </el-col>  """
                                } else if (it.jspTag == 'EDITOR') {
                                    println """  <el-col :span="7" :offset="1">
                        <el-form-item label="${it.cnname}" prop="${it.dataName}">
                            <el-input type="text" v-model="${
                                        PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)
                                    }AddForm.${it.dataName}">
                                                       <el-button slot="append" icon="el-icon-search" @click="rateVisible = true"></el-button>
                                                    </el-input>
                        </el-form-item>
                    </el-col>   """
                                }
                            }

                        }
                        columnsize ++;
                    }
                    println """  </el-row>  """;
                }
                println """  </div>
        </el-card>  """;
            }
        %>
        <div align="center" style="margin-top:15px;">
            <el-button type="primary" @click="submitForm('${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm')">提交</el-button>
            <el-button type="primary" @click="onCancel">取消</el-button>
        </div>
    </el-form>
</template>
<script>

    export default {
        name: '${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm',
        props: {},
        data() {
            return {
                ${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm: {},
                <%
                            println 'empName:this.$sessionStorage.getLoginUser().user.empName,';
                        %>
                rules: {
                    <%
                                cnt=1;
                                columns.each {
                                    if (cnt == columns.size()) {
                                        println """    ${it.dataName}: [
                                                            {required: true, message: '请自己填写', trigger: 'blur'}
                                                        ]    """;
                                    } else {
                                        if (pkColumn == it) {

                                        } else {
                                            println """    ${it.dataName}: [
                                                               {required: true, message: '请自己填写', trigger: 'blur'}
                                                           ],    """;

                                        }

                                        cnt++;
                                    }
                                }
                            %>
                },





            };
        },
        mounted: function () {
        },
        methods: {
            submitForm() {
                const _this = this;
                <%
                        println 'this.$refs.';
                        print """  ${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm.validate(valid => {
                                            if (!valid) {
                                                console.log("请检查表单！");
                                            } else {  """
                        println 'this.$http.post(';

                    %>
                "/loan/${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}Action.do?_md=update${PubUtils.toUpperTbNamesCase(tableDefine.dbTableName)}Selective", _this.${PubUtils.toLowerTbNamesCase(tableDefine.dbTableName)}AddForm)
            .then(function (response) {
                if (response.success) {
                    <%
                                    println '_this.$emit(';
                                    println """  "add${PubUtils.toUpperTbNamesCase(tableDefine.dbTableName)}Dialog");  """;
                                    println '_this.$emit("refreshTable");';
                                    println '_this.$success("修改成功！");';
                                %>
                } else{
                    <%
                                    println '_this.$error(response.msg);';
                                %>
                }
            })
                .catch(function (error) {
                    <%
                                println '_this.$error(error);';
                            %>
                });
    }
    });
    },
    onCancel() {
        <%
                println 'this.$success("已取消");';
                println 'this.$emit(';
                print '\'closeDialog\');';
            %>

    }
    },
    };

</script>
